package com.wkh.datastructure;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {8,3,6,1,3,632,63};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void sort(int[] arr){
        bubble(arr,arr.length-1);
    }
    private static void bubble(int[] arr,int j ){
        if (j == 0){
            return;
        }
        int x = 0;//表示有序和无序的边界
        for (int i = 0; i < j; i++) {
            if (arr[i]>arr[i+1]){
                int tem = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = tem;
                x = i;
            }
        }
        bubble(arr,x);
    }
}
